package com.augmentum.oes.common;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogMethodTime {
    private static final String exp = "execution(* com.augmentum.oes.service..*.*(..))";
    private final Logger log = Logger.getLogger(LogMethodTime.class);

    @Around(exp)
    public Object logAround(ProceedingJoinPoint pj) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = pj.proceed();
        long end = System.currentTimeMillis();
        String methodName = pj.getSignature().getName();
        log.debug(methodName + " takes " + (end - start) + "ms");
        return result;
    }
}
